package client.graphics 
{
	import ad.utils.createTextField;
	
	import __AS3__.vec.Vector;
	import flash.geom.Point;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	/**
	 * GRBalloon
	 * @version ActionScript 3.0
	 * @author Adrian C. Miranda
	 * @mail ad@adrianmiranda.com.br
	 */
	public class GRBalloon extends Sprite
	{
		private static const COLOR:uint = 0xFFFFFF;
		private static const BORDER:int = 6;
		private static const RADIUS:int = 3;
		
		public static const TOP_CENTER:String = 'topCenter';
		public static const DOWN_CENTER:String = 'downCenter';
		public static const LEFT_CENTER:String = 'leftCenter';
		public static const RIGHT_CENTER:String = 'rightCenter';
		
		private var _alignPointer:String = 'downCenter';
		
		public var pointer:Shape = addChild(new Shape()) as Shape;
		public var balloon:Sprite = addChild(new Sprite()) as Sprite;
		public var textField:TextField = createTextField();
		
		public function GRBalloon()
		{
			super();
			draw();
		}
		
		private function draw():void
		{
			addChild(textField);
		}
		
		public function get alignPointer():String { return _alignPointer }
		public function set alignPointer(value:String):void 
		{
			_alignPointer = value;
		}
		
		public function get text():String { return textField.text; }
		public function set text(value:String):void 
		{
			textField.htmlText = value;
			with (balloon)
			{
				graphics.clear();
				graphics.beginFill(COLOR, 1);
				graphics.drawRoundRectComplex(0, 0, textField.textWidth + (BORDER * 2), textField.textHeight + (BORDER * 2), RADIUS, RADIUS, RADIUS, RADIUS);
				graphics.endFill();
			}
			with (textField)
			{
				x = (balloon.width / 2) - (width / 2);
				y = (balloon.height / 2) - (height / 2);
			}
			with (pointer)
			{
				graphics.clear();
				graphics.beginFill(COLOR, 1);
				graphics.moveTo(0, 0);
				graphics.lineTo(8, 0);
				graphics.lineTo(4, 4);
				graphics.lineTo(0, 0);
				graphics.endFill();
				switch (_alignPointer) 
				{
					case GRBalloon.TOP_CENTER:
						rotation = 180;
						x = (balloon.x + (balloon.width / 2) + (width / 2));
						y = (balloon.y);
					break;
					
					case GRBalloon.RIGHT_CENTER:
						rotation = -90;
						x = (balloon.x + balloon.width);
						y = (balloon.y + (balloon.height / 2) + (height / 2));
					break;
					
					case GRBalloon.DOWN_CENTER:
						x = (balloon.x + (balloon.width / 2) - (width / 2));
						y = (balloon.y + balloon.height);
					break;
					
					case GRBalloon.LEFT_CENTER:
						rotation = 90;
						x = (balloon.x);
						y = (balloon.y + (balloon.height / 2) - (height / 2));
					break;
				}
			}
		}
		
	}

}